
import $http from "./index"
import url from "./url"
import type { AxiosResponse } from "axios";

export function login(body: LoginForm): Promise<AxiosResponse<LoginRes>> {
    return $http.post(url.LOGIN, body)
}

export function password(body: PassForm): Promise<AxiosResponse<Res>> {
    return $http.put(url.PASSWORD, body)
}

export function getRole(query: CommonQuery): Promise<AxiosResponse<DataRes<RoleData>>> {
    return $http.get(url.ROLE, query)
}
export function getRoleById(id: number): Promise<AxiosResponse<DataRes<RoleData>>> {
    return $http.get(url.ROLE+"/"+id)
}
// 新增角色
export function addRole(body: RoleForm): Promise<AxiosResponse<Res>> {
    return $http.post(url.ROLE, body)
}

export function findbyrid(rid: number): Promise<AxiosResponse<Res>> {
    return $http.get(url.FINDBYRID, { rid })
}

export function delRole(rid: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.ROLE+"/"+rid)
}

export function delManager(id: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.MANAGER+"/"+id)
}

export function edtRole(id: number,body:Partial<RoleForm>): Promise<AxiosResponse<Res>> {
    return $http.put(url.ROLE+"/"+id,body)
}

export function edtManager(id: number,body:Partial<RoleForm>): Promise<AxiosResponse<Res>> {
    return $http.put(url.MANAGER+"/"+id,body)
}

export function getManager(query:ManagerQuery): Promise<AxiosResponse<DataRes<ManagerData>>> {
    return $http.get(url.MANAGER, query)
}
export function addManager(body: ManagerForm): Promise<AxiosResponse<Res>>  {
    return $http.post(url.MANAGER, body)
}

export function getCustomer(query: CustomerQuery): Promise<AxiosResponse<DataRes<CustomerData>>> {
    return $http.get(url.CUSTOMER, query)
}
export function addCustomer(body: CustomerData): Promise<AxiosResponse<Res>>  {
    return $http.post(url.CUSTOMER, body)
}
export function delcustomer(id: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.CUSTOMER+"/"+id)
}
export function edtcustomer(id: number,body:CustomerData): Promise<AxiosResponse<Res>> {
    return $http.put(url.CUSTOMER+"/"+id,body)
}

// CONTRACT
export function getContract(query: ContractQuery): Promise<AxiosResponse<DataRes<ContractData>>> {
    return $http.get(url.CONTRACT, query)
}
export function addContract(body: ContractData): Promise<AxiosResponse<Res>>  {
    return $http.post(url.CONTRACT, body)
}
export function delContract(id: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.CONTRACT+"/"+id)
}
export function edtContract(id: number,body:ContractData): Promise<AxiosResponse<Res>> {
    return $http.put(url.CONTRACT+"/"+id,body)
}

// MENU
export function getMenu(query: MenuQuery): Promise<AxiosResponse<DataRes<BannerData[]>>> {
    return $http.get(url.MENU, query)
}
export function addMenu(body: BannerData): Promise<AxiosResponse<Res>>  {
    return $http.post(url.MENU, body)
}
export function delMenu(id: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.MENU+"/"+id)
}
export function edtMenu(id: number,body:BannerData): Promise<AxiosResponse<Res>> {
    return $http.put(url.MENU+"/"+id,body)
}

// 轮播管理
export function getBanner(query: CommonQuery): Promise<AxiosResponse<DataRes<BannerData[]>>> {
    return $http.get(url.BANNER, query)
}
export function addBanner(body: BannerData): Promise<AxiosResponse<Res>>  {
    return $http.post(url.BANNER, body)
}
export function delBanner(id: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.BANNER+"/"+id)
}
export function edtBanner(id: number,body:BannerForm): Promise<AxiosResponse<Res>> {
    return $http.put(url.BANNER+"/"+id,body)
}

// 分类管理
export function getClassify(query: CommonQuery): Promise<AxiosResponse<DataRes<ClassifyData[]>>> {
    return $http.get(url.CLASSIFY, query)
}
export function addClassify(body: ClassifyData): Promise<AxiosResponse<Res>>  {
    return $http.post(url.CLASSIFY, body)
}
export function delClassify(id: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.CLASSIFY+"/"+id)
}
export function edtClassify(id: number,body:ClassifyForm): Promise<AxiosResponse<Res>> {
    return $http.put(url.CLASSIFY+"/"+id,body)
}

// 分类管理
export function getGoods(query: CommonQuery): Promise<AxiosResponse<DataRes<GoodsData[]>>> {
    return $http.get(url.GOODS, query)
}
export function addGoods(body: GoodsData): Promise<AxiosResponse<Res>>  {
    return $http.post(url.GOODS, body)
}
export function delGoods(id: number): Promise<AxiosResponse<Res>> {
    return $http.delete(url.GOODS+"/"+id)
}
export function edtGoods(id: number,body:GoodsForm): Promise<AxiosResponse<Res>> {
    return $http.put(url.GOODS+"/"+id,body)
}